package com.example.misqliteapp;

import java.util.ArrayList;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListActivity extends Activity {

	ListView lista;
	MiAdministradorSQLite admin;
	ArrayList<String> list = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list);

		lista = (ListView) findViewById(R.id.listview);

		admin = new MiAdministradorSQLite(this, "mibase", null, 1);

		consultar();

		ArrayAdapter adapter = new ArrayAdapter(this,
				android.R.layout.simple_list_item_1, list);
		lista.setAdapter(adapter);
	}

	public void consultar() {

		SQLiteDatabase bd = admin.getReadableDatabase();

		Cursor fila = bd.rawQuery("select nombre from persona", null);
		while (fila.moveToNext()) {
			list.add(fila.getString(0));
		}

		bd.close();

	}

}
